package it.unina.uninachi;

import android.os.Bundle;

import android.os.Handler;
import android.os.Message;
import java.io.*;

public class TerminaThread extends Thread {
	
	protected Handler handler;
	protected DataInputStream in;
	protected DataOutputStream out;
	
	public TerminaThread(Handler H){
		handler = H;
		try {
			in = new DataInputStream(WaitConnection.socket.getInputStream());
			out = new DataOutputStream(WaitConnection.socket.getOutputStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void run(){
		try {
			//protocollo: terminazione gioco improvvisa
			out.writeUTF("TERMINA_END"); //mando la terminazione;
			Message msg = handler.obtainMessage();
			Bundle b = new Bundle();
	    	b.putString("TERMINA", "");
		    msg.setData(b);
		    WaitConnection.socket.close();
		    handler.sendMessage(msg);	    	
		} catch (IOException e) {

			e.printStackTrace();
		}	
	}
}
